using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;

namespace miciv.Rendering
{
    public class VertexDefinitionManager : HashtableManager<string, VertexDefinition>
    {
        protected CoreContext m_coreContext;

        public VertexDefinitionManager(CoreContext _coreContext)
        {
            this.m_coreContext = _coreContext;
        }

        public void LoadVertexDefinitions(string _strLocation)
        {
            string[] strDefinitions = Directory.GetFiles(_strLocation, "*.xml");
            foreach (string strDefinition in strDefinitions)
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(strDefinition);
                VertexDefinition vertexDefinition = new VertexDefinition(xmlDocument.DocumentElement.SelectSingleNode("vertexdefinition") as XmlElement);
                if (null != this.m_coreContext.GetData<VertexDefinition>(vertexDefinition.ID))
                {
                    throw new Exception(string.Format("{0} already present in context.", vertexDefinition.ID));
                }
                this.Add(vertexDefinition.ID, vertexDefinition);
            }
        }
    }
}
